/**
 * related to repairInfo.ui
 * 
 * @Author : 2037630@163.com
 * @Timestamp : 2017-04-19
 */
var notify = sm("do_Notification");
var Controller = require("core/controller");
var log = require("util/log")
var device=require("util/device")
var navigate = require("util/navigate")
var router = require("config/router")
var server = require('config/server');
var net = require("util/net");
var page = sm("do_Page");
var dialog=sm("do_Dialog");
Controller({
	config : {
		header : {
			title : '逾期还款'
		}
	},
	mapping : {
		"ov_rpSumMoney.text":"ovInfo.ov_rpSumMoney",
		"ov_rpMoney.text":"ovInfo.ov_rpMoney",
		"ov_reduMoney.text":"ovInfo.ov_reduMoney",
		"ov_remark.text":"ovInfo.ov_remark",
		"com_repayType.items" : "ovInfo.com_repayType|getTypeCodeData",
		"com_repayType.value" : "ovInfo.com_repayTypeValue",
		"cas_repayTop.items" : "ovInfo.cas_repayTop|getTypeCodeData",
		"cas_repayTop.value" : "ovInfo.cas_repayTopValue",
//		"ove_leftImg.source":"ovInfo.ove_leftImg",
//		"ove_rightImg.source":"ovInfo.ove_rightImg"
	},
	data : {
		dataOver:'',
		ovInfo : {
			ov_rpMoney:"",
			ov_reduMoney:"",
			ov_remark:"",
			com_repayType: "0027",
			com_repayTypeValue:"103",
			cas_repayTop:"0032",
			cas_repayTopValue:"130",
//			cupoId:page.getData().cupoId,
			ov_rpSumMoney:"",
//			ove_leftImg:"",
//			ove_rightImg:""
		},
		dialogData:{},
		oveList:[],
		rpayMoney:{}
	},
	ui: {
		btn_confirm:"btn_confirm",
		layout_redu:"layout_redu",
		ov_remark:"ov_remark",
		ov_rpMoney:"ov_rpMoney",
		ov_reduMoney:"ov_reduMoney",
		root:"$"
	},
	event : {
		'btn_confirm':{
			'touch':function(){
				if(this.data.ovInfo.ov_rpMoney.length>0){
					if((this.data.ovInfo.ov_reduMoney-288.88)<=0){
						this.submitOvRepay()
					}else {
						notify.toast('减免金额应为0-288.88')	
					}
				}else{
					notify.toast('还款金额不能为空')
				}
			}
		},
		'dialog':{
			'touch':function(){
				dialog.open('source://view/dialog/overpay_dialog.ui',this.data.dialogData)
			}
		},
		'over_upload':{
			'touch':function(){
				device.uploadImage({
					width: 480,
					height: 720,
					iscut:false,
					quality:100,
					scope:this
					}, this.over_upLoad)
			}
		},
		'cas_repayTop':{
			'selectChanged':function(){
				log.info(588,this.data)
				log.info(this.data.ovInfo.cas_repayTopValue)
				if(this.data.ovInfo.cas_repayTopValue==130){
					this.ui.ov_remark.visible=false
					this.ui.layout_redu.visible=false
					this.ui.ov_rpMoney.enabled=true
					this.ui.ov_rpMoney.text=""
					this.ui.root.redraw()
				}else if (this.data.ovInfo.cas_repayTopValue==131) {
					this.ui.ov_remark.visible=false
					this.ui.layout_redu.visible=false
					this.ui.ov_rpMoney.text=this.data.dataOver.cop.cupoAmt
					this.data.rpayMoney=parseInt(this.data.dataOver.cop.cupoAmt)
					this.ui.ov_rpMoney.enabled=false
					this.ui.ov_rpMoney.fontColor="#000000FF"
					this.ui.btn_confirm.bgColor="#28313eFF"
					this.ui.root.redraw()
				}else {
					this.ui.ov_remark.visible=true
					this.ui.layout_redu.visible=true
					this.ui.ov_rpMoney.enabled=false
					this.ui.ov_rpMoney.fontColor="#000000FF"
					this.ui.btn_confirm.bgColor="#A9A9A9FF"
					this.ui.root.redraw()
				}
				
			}
		},
		'ov_reduMoney':{
			'textChanged':function(){
				this.ui.ov_rpMoney.text=(parseInt(this.data.dataOver.cop.cupoAmt)-this.ui.ov_reduMoney.text).toFixed(2)
				this.data.rpayMoney=(parseInt(this.data.dataOver.cop.cupoAmt)-this.data.ovInfo.ov_reduMoney).toFixed(2)
//				log.info(56654,this.data.rpMoney)
				if ((this.data.ovInfo.ov_reduMoney-288.88)>0) {
					notify.toast('减免金额应为0-288.88')
				}
				this.ui.btn_confirm.bgColor="#28313eFF"
			}
		},
		'ov_rpMoney':{
			'textChanged':function(){
				this.ui.btn_confirm.bgColor="#28313eFF"
			}
		}
	},
	methods : {
		over_upLoad:function(path){
			this.data.oveList.push(path.id)	
	//			this.refresh('$')
		},
		myOver:function(myover){
			this.data.ovInfo.ov_rpSumMoney=myover.cop.cupoAmt
			this.refresh('$')
		},
		submitOvRepay : function() {
			log.info(5655,this.data.ovInfo.ov_rpMoney)
			net.send({
				server:server.organization.overDayRepyMoney,
				data:{
					"cupoId": this.data.dataOver.cop.cupoId,
					  "derateDescripton": this.data.ovInfo.ov_remark,
					  "derateFee": this.data.ovInfo.ov_reduMoney,
					  "fileIds":this.data.oveList,
					  "payAmt": this.data.ovInfo.ov_rpMoney,
					  "payaType": this.data.ovInfo.cas_repayTopValue,
					  "paymentType": this.data.ovInfo.com_repayTypeValue
				},
				success:function(){	
					notify.toast("提交成功")
					navigate.back("6666")
				},
				error : function(data) {
					notify.toast(data.reason)
				},
				scope:this
			})
		}
	},
	loaded : function(data) {
		log.info(111,data,222)
		this.data.dataOver = data
		log.info(111,this.data.dataOver,222)
		this.myOver(this.data.dataOver)
		var get_data=page.getData().cupoOrdernum;
		log.info(get_data);
		net.send({
			server:server.organization.openDialog,
			data:{
				'orderNum':get_data
			},
			success:function(data){
				for(i in data){
					if(data[i]==null){
						data[i]=''
					}
				}
				log.info(data)
				this.data.dialogData=data
				log.info(this.data.dialogData)
			},
			error:function(){
			},
			scope:this
		})
	},
})